package com.jiexinyun.utils;

import java.sql.Timestamp;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

public class CustomizDateUtils {

    public static void main(String[] args) {
        getTodayStart();
        getTodayEnd();
    }

    public static Timestamp generateBilldate() {
        // 1. 获取当天日期
        LocalDate today = LocalDate.now();

        // 2. 转换为当天的00:00:00时间
        LocalDateTime midnight = today.atStartOfDay();

        // 3. 格式化为字符串 (可选步骤，如果需要字符串表示)
//        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
//        String formattedDate = midnight.format(formatter);
//        System.out.println("格式化后的日期字符串: " + formattedDate);

        // 4. 直接转换为Timestamp
        Timestamp timestamp = Timestamp.valueOf(midnight);

        System.out.println("最终的Timestamp: " + timestamp);
        System.out.println("Timestamp毫秒数: " + timestamp.getTime());
        return timestamp;
    }


    public static Timestamp getTodayStart() {
        // 1. 获取当天日期
        LocalDate today = LocalDate.now();

        // 2. 转换为当天的00:00:00时间
        LocalDateTime midnight = today.atStartOfDay();

        // 3. 格式化为字符串 (可选步骤，如果需要字符串表示)
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String formattedDate = midnight.format(formatter);
        System.out.println("格式化后的日期字符串: " + formattedDate);

        // 4. 直接转换为Timestamp
        Timestamp timestamp = Timestamp.valueOf(midnight);

        System.out.println("最终的Timestamp: " + timestamp);
        System.out.println("Timestamp毫秒数: " + timestamp.getTime());
        return timestamp;
    }

    public static Timestamp getTodayEnd() {
        // 1. 获取当天日期
        LocalDate today = LocalDate.now();

        // 2. 转换为当天的23:59:59.999时间 当天结束时间
        LocalDateTime endOfDay = today.atTime(LocalTime.MAX);
        System.out.println("当天结束时间: " + endOfDay);

        // 3. 格式化为字符串 (可选步骤，如果需要字符串表示)
//        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
//        String formattedDate = midnight.format(formatter);
//        System.out.println("格式化后的日期字符串: " + formattedDate);

        // 4. 直接转换为Timestamp
        Timestamp timestamp = Timestamp.valueOf(endOfDay);

        System.out.println("最终的Timestamp: " + timestamp);
        System.out.println("Timestamp毫秒数: " + timestamp.getTime());
        return timestamp;
    }

    public static final String yyyy_MM_ddStrCur() {
        LocalDate today = LocalDate.now();
        // 格式化为 yyyy-MM-dd 字符串
        return today.format(DateTimeFormatter.ISO_DATE);
    }

}
